package com.guqj.basis.sort;

import java.util.Arrays;

public class ForOnceSort {

	public static void main(String[] args) {
		int[] arr = new int[] { 56, 82, 12, 59 };
		System.out.println("排序前: " + Arrays.toString(arr));
		sort(arr);
		System.out.println("排序后: " + Arrays.toString(arr));
	}

	/**
	 * 一个for循环，进行排序
	 * @param arr
	 */
	public static void sort(int[] arr) {
		int times = arr.length - 1;
		for (int i = 0; i < times; i++) {
			if (arr[i] > arr[i + 1]) {
				int temp = arr[i + 1];
				arr[i + 1] = arr[i];
				arr[i] = temp;
			}

			if (i == times - 1) {
				i = -1;
				times--;
			}
		}
	}
}
